<?php


namespace app\admin\model;



use app\home\model\User;
use think\Db;
use think\Model;

class Login extends Model
{
    protected $table = 'hb_auser';
    protected $pk = 'id';
    
    public function check($p)
    {
        $pass=hash('sha1',$p['pass']);
        $result=Db::table('hb_auser')
            ->field('id')
            ->where('username',$p['username'])
            ->where('pass',$pass)
            ->find();
        return $result;
    }


    //获取分类列表
    public function getCate()
    {
        $result = Db::table('hb_category')->paginate(8);
        return $result;
    }

    public function getDetail($id)
    {
        $row = Db::table('hb_user')->where('id=' . $id)->find();

        $row['sex'] = ($row['sex'] == 1) ? '男' : '女';

        $row['status'] = ($row['status'] == 1) ? '激活' : '禁用';

        $row['regtime'] = date('Y/m/d H:i:s', $row['regtime']);

        return $row;

    }

    public function addC($arr)
    {
        $data = db('category')->where('category_name',$arr['category_name'])->select();
        if($data){
            return false;
        }
        $row = db('category')->insertGetId($arr);
        if($row){
            return $row;
        }else{
            return false;
        }
    }
}
